package com.jiyuanime.particle;

import java.awt.*;

public class Particle
{
    private int x;
    private int y;
    private final int dx;
    private final int dy;
    private final int size;
    private int life;
    private final Color c;

    public Particle(final int x, final int y, final int dx, final int dy, final int size, final int life, final Color c) {
        this.x = x;
        this.y = y;
        this.dx = dx;
        this.dy = dy;
        this.size = size;
        this.life = life;
        this.c = c;
    }

    public boolean update() {
        this.x += this.dx;
        this.y += this.dy;
        --this.life;
        return this.life <= 0;
    }

    public void render(final Graphics g) {
        if (this.life > 0) {
            final Graphics2D g2d = (Graphics2D) g.create();
            g2d.setColor(this.c);
            g2d.fillRect(this.x - this.size / 2, this.y - this.size / 2, this.size, this.size);
            g2d.dispose();
        }
    }

    @Override
    public String toString() {
        return "Particle{x=" + this.x + ", y=" + this.y + ", dx=" + this.dx + ", dy=" + this.dy + ", size=" + this.size + ", life=" + this.life + ", c=" + this.c + '}';
    }
}
